<html>
	<?php
		require_once("classes/User.php");
		require_once("classes/Database.php");
		require_once("classes/Head.php");
		require_once("classes/Section.php");
		require_once("classes/Image.php");
		require_once("classes/Title.php");
		require_once("classes/Paragraph.php");
		require_once("classes/LinkList.php");
		require_once("classes/EntryList.php");
		require_once("classes/Announcement.php");
		require_once("classes/Form.php");
		
		$head = new Head();
		
		if(!isset($_SESSION["login"])){
			session_start();
		}
		
		$user = $_SESSION["user"];
		if($_SESSION["login"]){
			$title = "Meus Posts";
		}else{
			$title = "Login Errado";
		}
		$head->addLayout("css/style.css");
		$head->addTitle($title);
		
		$head->printHead();
	?>
	<body id="body">
		<div id="struture">
			<div id="container">
		        <?php
		        
		        	$header = new Section("header");					
						$header->addElement(new Image("images/job.png", "logo", "100px", "100px"));
						
						$title = new Title("Ofertas de Emprego", "title");
						$header->addElement($title);
					$header->printSection();
		        	
		        	/* Left Page */
		        	$leftPage = new Section("leftPage");
					if($_SESSION["login"]){
						$leftPage->addElement(new Title("Candidato", "menuTitle"));
						
						$leftPage->addElement(new Paragraph("Veja os seus posts.</br>Se pretender eliminar algum dever&aacute entrar no anuncio onde colocou o post.", "menu"));
						$logout = new LinkList("menuEntry");
						$logout->addLink("Logout", "scripts/logout.php", new Image("images/leave.png", "icon", "16px", "16px"));
						$logout->addLink("Voltar", "home.php", new Image("images/leave.png", "icon", "16px", "16px"));
						$leftPage->addElement($logout);
						
						$leftPage->printSection();
						
						$content = new Section("content");
						
						$content->addElement(new Title("Posts de ".$user->getName(), "seccaoTitle"));
						$id = $user->getId();
						$nome = $user->getName();
						$db = new Database("localhost", "root", "");
						$db->connect("emprego");
						$db->executeQuery("SELECT announcement, content, save_date FROM posts WHERE candidate='$id'");
						if($line = $db->getResultLine(MYSQL_ASSOC)){
							$entry = new EntryList("entry");
							do{
								$entry->openEntry();
								$entry->addLinkTitle("announcement.php?ad=".$line["announcement"], $nome." --- ".$line["save_date"]." -&gt Ver anuncio");
								$entry->addEntry("", $line["content"]);
								$entry->closeEntry();
								$entry->addHtmlCode("</br></br>");
							}while($line = $db->getResultLine(MYSQL_ASSOC));
							$db->disconnect();
							$content->addElement($entry);
						}else{
							$content->addElement(new Paragraph("Nenhum post encontrado, pesquise um anuncio e faça um post.", "seccao"));
						}
						$content->printSection();
					}else{
						$text = "Login Errado.";
						$leftPage->addElement(new Title("ERRO", "menuTitle"));
						$leftPage->addElement(new Paragraph($text, "menu"));
						
						$leave = new LinkList("menuEntry");
						$leave->addLink("Voltar", "index.php", new Image("images/leave.png", "icon", "16px", "16px"));
						$leftPage->addElement($leave);
						$leftPage->printSection();
						
						$content = new Section("content");
						$content->addElement(new Title("ERRO", "seccaoTitle"));
						
						$content->printSection();
					}
					
					$footer = new Section("footer");
						$text = new Paragraph("Copyright&copy Nuno Pombo", "");
						$footer->addElement($text);
					$footer->printSection();
		        ?>
			</div>
		</div>
	</body>
</html>